home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / system / pgraf130.zip / C.ZIP / DEMO_SUB.C next >
Text File  |  1991-07-09  |  27KB  |  888 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <fonts.h>
  5. #ifdef __TURBOC__
  6. #include <alloc.h>
  7. #endif
  8.  
  9. #if defined(__HUGE__) || defined(__LARGE__) || defined(__MEDIUM__)
  10. #define LARGE_CODE
  11. #endif
  12.  
  13. #define MAX_WIDTH 801            /* Maximum width of any PGRAPH viewport defined in the program */
  14.  
  15. extern int page_height, page_width;    /* Size of page in pixels */
  16. extern int prn;                            /* Output device */
  17.  
  18. void end_slice(void);
  19. #if defined(LARGE_CODE)
  20. void start_screen_output(void);
  21. void stop_screen_output(void);
  22.  
  23. #ifdef __TURBOC__
  24. #include <graphics.h>
  25. #include <bgidrive.h>
  26. #define CLS cleardevice()
  27. #else
  28. #include <graph.h>
  29. #define CLS _clearscreen(0)
  30. #endif
  31. #endif
  32.  
  33. #include "pgraph.h"
  34.  
  35.  
  36. /********************************************************************
  37.  Draw lines, ellipses, polygons, move graphics cursor */
  38.  
  39. void shapes_demo(void)
  40. {
  41. int xasp, yasp;
  42. int xres, yres;
  43. int error_code;
  44. int width, height;
  45. long free_space;
  46. struct arccoordstype arccoords;
  47. static int polypoints[14] = {
  48.     500, 160,
  49.     500, 340,
  50.     450, 250,
  51.     400, 250,
  52.     350, 330,
  53.     360, 170,
  54.     500, 160};
  55.  
  56.     printf("\n\nSHAPES DEMO\n\n");
  57.     p_getresolution(&xres, &yres);
  58.     p_setviewport(0, 0, 0, 0, 1);
  59. #ifdef __TURBOC__
  60.     free_space = farcoreleft() - 0x4000L;       /* Leave room for other graph memory uses */
  61. #else
  62.     free_space = 409600L;                   /* Take 400K */
  63. #endif
  64.     width = (int)((long)xres * page_width / 100);
  65.     height = (int) (free_space * 8 / width);
  66.     height = min(height, (int)((long)yres * page_height / 100));
  67.     printf("Setting %d by %d pixel (%d*%d inches) viewport\n",
  68.         width, height, width/xres, height/yres);
  69.     p_setviewport(0, 0, width - 1, height - 1, 1);
  70.     error_code = p_graphresult();
  71.     if (error_code != grOk || height < 340) {
  72.         printf("Failed... Insufficient memory\n");
  73.         return;
  74.     }
  75.     p_setlinestyle(USERBIT_LINE, 0x8080, NORM_WIDTH);
  76.     p_rectangle(0, 0, p_getmaxx(), p_getmaxy());
  77.     p_setlinestyle(CENTER_LINE, 0, NORM_WIDTH);
  78.     printf("p_drawpoly(7, polypoints);\n");
  79.     p_drawpoly(7, polypoints);
  80.     printf("p_rectangle(220, 140, 270, 10);\n");
  81.     p_rectangle(220, 240, 270, 110);
  82.     printf("p_circle(p_getmaxx() - 120, 100, 100);\n");
  83.     p_circle(p_getmaxx() - 120, 100, 100);
  84.     printf("p_arc(p_getmaxx() - 220, 100, 45, 135, 100);\n");
  85.     p_arc(p_getmaxx() - 220, 100, 45, 135, 100);
  86.     p_getarccoords(&arccoords);
  87.     printf("Last arc centred at (%d, %d), from (%d, %d) to (%d, %d)\n",
  88.         arccoords.x, arccoords.y, arccoords.xstart, arccoords.ystart,
  89.         arccoords.xend, arccoords.yend);
  90.     printf("p_ellipse(90, 10, 0, 360, 30, 10);\n");
  91.     p_ellipse(90, 10, 0, 360, 30, 10);
  92.     printf("p_ellipse(160, 10, 0, 360, 5, 10);\n");
  93.     p_ellipse(160, 10, 0, 360, 5, 10);
  94.     printf("p_ellipse(200, 10, 45, 135, 30, 10);\n");
  95.     p_ellipse(200, 10, 45, 135, 30, 10);
  96.     printf("p_ellipse(240, 10, 45, 135, 5, 10);\n");
  97.     p_ellipse(240, 10, 45, 135, 5, 10);
  98.     printf("p_ellipse(280, 10, 45, 225, 30, 10);\n");
  99.     p_ellipse(280, 10, 45, 225, 30, 10);
  100.     printf("p_getaspectratio(&xasp, &yasp);\np_setaspectratio(xasp, yasp/3);\n");
  101.     p_getaspectratio(&xasp, &yasp);
  102.     p_setaspectratio(xasp, yasp/3);
  103.     printf("Same circle and arc as above, but Ycentre at 390\n");
  104.     p_circle(p_getmaxx() - 120, 390, 100);
  105.     p_arc(p_getmaxx() - 220, 390, 45, 135, 100);
  106.     printf("Width = %d, Height = %d\n", p_getmaxx(), p_getmaxy());
  107.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  108.     printf("p_moveto(40, 50);\n");
  109.     p_moveto(40, 50);
  110.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  111.     printf("p_moverel(+20, -10);\n");
  112.     p_moverel(+20, -10);
  113.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  114.  
  115.     printf("Various ellipse fragments\n");
  116.     p_ellipse(450, 60,   0,  20, 100, 50);
  117.     p_ellipse(450, 60,  30,  60, 100, 50);
  118.     p_ellipse(450, 60,  70,  90, 100, 50);
  119.     p_ellipse(450, 60,  90, 110, 100, 50);
  120.     p_ellipse(450, 60, 120, 150, 100, 50);
  121.     p_ellipse(450, 60, 160, 180, 100, 50);
  122.     p_ellipse(450, 60, 180, 200, 100, 50);
  123.     p_ellipse(450, 60, 210, 240, 100, 50);
  124.     p_ellipse(450, 60, 250, 270, 100, 50);
  125.     p_ellipse(450, 60, 270, 290, 100, 50);
  126.     p_ellipse(450, 60, 300, 330, 100, 50);
  127.     p_ellipse(450, 60, 340, 360, 100, 50);
  128.     p_ellipse(100, 140, 20, 340, 100, 50);
  129.  
  130.     printf("Lines\n");
  131.     p_setlinestyle(DASHED_LINE, 0, NORM_WIDTH);
  132.     p_line(100, 140, 200, 140);
  133.     p_line(100, 140, 100, 90);
  134.     p_line(0, 200, 10, 250);
  135.     p_line(0, 200, 50, 210);
  136.     p_line(50, 210, 0, 220);
  137.     p_line(50, 210, 40, 250);
  138.     p_moveto(450, 60);
  139.     p_linerel(100, 0);
  140.     p_lineto(450, 110);
  141.  
  142.     printf("Pixels\n");
  143.     p_putpixel(319, 0, 1);
  144.     p_putpixel(319, 1, 1);
  145.     p_putpixel(319, 1, 0);
  146.     end_slice();
  147. }
  148.  
  149. /********************************************************************
  150.  Register stroked fonts, and print them in different sizes and
  151.  orientations */
  152.  
  153. void stroked_fonts_demo(void)
  154. {
  155. int goth_height, next_line;
  156.  
  157.     printf("\n\nSTROKED FONTS DEMO\n\n");
  158.     p_setviewport(0, 0, 719, 170, 1);
  159.     p_registerbgifont(gothic_font);
  160. #if !defined(__TINY__)
  161.     p_registerfarbgifont(script_font_far);
  162. #endif
  163.     printf("Printing text size 1, horizontally\n");
  164.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 1);
  165.     p_outtextxy(0, 0, "Gothic 1");
  166.     goth_height = p_textheight("Gothic 1");
  167.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 1);
  168.     p_outtextxy(200, 0, "Script 1");
  169.     next_line = max(p_textheight("Script 1"), goth_height);
  170.  
  171.     printf("Printing text size 1, vertically\n");
  172.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 1);
  173.     p_outtextxy(360, 0, "Gothic 1");
  174.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 1);
  175.     p_outtextxy(380, 0, "Script 1");
  176.  
  177.     printf("Printing text size 2, horizontally\n");
  178.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 2);
  179.     p_outtextxy(0, next_line, "Gothic 2");
  180.     goth_height = p_textheight("Gothic 2");
  181.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 2);
  182.     p_outtextxy(200, next_line, "Script 2");
  183.     next_line += max(p_textheight("Script 2"), goth_height);
  184.  
  185.     printf("Printing text size 2, vertically\n");
  186.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 2);
  187.     p_outtextxy(410, 0, "Gothic 2");
  188.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 2);
  189.     p_outtextxy(430, 0, "Script 2");
  190.  
  191.     printf("Printing text size 3, horizontally\n");
  192.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 3);
  193.     p_outtextxy(0, next_line, "Gothic 3");
  194.     goth_height = p_textheight("Gothic 3");
  195.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
  196.     p_outtextxy(200, next_line, "Script 3");
  197.     next_line += max(p_textheight("Script 3"), goth_height);
  198.  
  199.     printf("Printing text size 3, vertically\n");
  200.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 3);
  201.     p_outtextxy(465, 0, "Gothic 3");
  202.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 3);
  203.     p_outtextxy(500, 0, "Script 3");
  204.  
  205.     printf("Printing text size 4, horizontally\n");
  206.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 4);
  207.     p_outtextxy(0, next_line, "Gothic 4");
  208.     goth_height = p_textheight("Gothic 4");
  209.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
  210.     p_outtextxy(200, next_line, "Script 4");
  211.     next_line += max(p_textheight("Script 4"), goth_height);
  212.  
  213.     printf("Printing text size 4, vertically\n");
  214.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 4);
  215.     p_outtextxy(540, 0, "Gothic 4");
  216.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 4);
  217.     p_outtextxy(580, 0, "Script 4");
  218.  
  219.     printf("Printing text size 5, horizontally\n");
  220.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 5);
  221.     p_outtextxy(0, next_line, "Gothic 5");
  222.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 5);
  223.     p_outtextxy(200, next_line, "Script 5");
  224.  
  225.     printf("Printing text size 5, vertically\n");
  226.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 5);
  227.     p_outtextxy(620, 0, "Gothic 5");
  228.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 5);
  229.     p_outtextxy(660, 0, "Script 5");
  230.  
  231.     end_slice();
  232.  
  233.     p_setviewport(0, 0, 550, 240, 1);
  234.     printf("Printing text size 9, horizontally\n");
  235.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 9);
  236.     p_outtextxy(0, 0, "Gothic 9");
  237.     next_line = p_textheight("Gothic 9");
  238.  
  239.     printf("Printing text size 10, horizontally\n");
  240.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 10);
  241.     p_outtextxy(0, next_line, "Gothic 10");
  242.  
  243.     end_slice();
  244. }
  245.  
  246. /********************************************************************
  247.  Print default font in various sizes and orientations */
  248. void default_font_demo(void)
  249. {
  250.     printf("\n\nDEFAULT FONT DEMO\n\n");
  251.     p_setviewport(0, 0, 680, 199, 1);
  252.     printf("Printing text size 1, horizontally\n");
  253.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  254.     p_outtextxy(0, 0, "Default 1");
  255.     printf("Printing text size 1, vertically\n");
  256.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 1);
  257.     p_outtextxy(360, 0, "Default 1");
  258.  
  259.     printf("Printing text size 2, horizontally\n");
  260.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
  261.     p_outtextxy(0, 18, "Default 2");
  262.     printf("Printing text size 2, vertically\n");
  263.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 2);
  264.     p_outtextxy(378, 0, "Default 2");
  265.  
  266.     printf("Printing text size 3, horizontally\n");
  267.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 3);
  268.     p_outtextxy(0, 40, "Default 3");
  269.     printf("Printing text size 3, vertically\n");
  270.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 3);
  271.     p_outtextxy(416, 0, "Default 3");
  272.  
  273.     printf("Printing text size 4, horizontally\n");
  274.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 4);
  275.     p_outtextxy(0, 65, "Default 4");
  276.     printf("Printing text size 4, vertically\n");
  277.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 4);
  278.     p_outtextxy(468, 0, "Default 4");
  279.  
  280.     printf("Printing text size 5, horizontally\n");
  281.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 5);
  282.     p_outtextxy(0, 100, "Default 5");
  283.     printf("Printing text size 5, vertically\n");
  284.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 5);
  285.     p_outtextxy(520, 0, "Default 5");
  286.  
  287.     printf("Printing text size 6, horizontally\n");
  288.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 6);
  289.     p_outtextxy(0, 150, "Default 6");
  290.     printf("Printing text size 6, vertically\n");
  291.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 6);
  292.     p_outtextxy(620, 0, "Default 6");
  293.  
  294.     end_slice();
  295.  
  296.     p_setviewport(0, 0, 800, 89, 1);
  297.     printf("Printing text size 10, horizontally\n");
  298.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 10);
  299.     p_outtextxy(0, 0, "Default 10");
  300.  
  301.     end_slice();
  302. }
  303.  
  304. /********************************************************************
  305.  Print stroked and default font horizontally, using various
  306.  justification settings */
  307.  
  308. void horiz_text_demo(void)
  309. {
  310. int i;
  311.  
  312.     printf("\n\nHORIZONTAL JUSTIFICATION DEMO\n\n");
  313.     p_setviewport(0, 0, 760, 175, 1);
  314.     p_setlinestyle(DOTTED_LINE, 0, NORM_WIDTH);
  315.     for (i = 25; i <= 150; i += 25)
  316.         p_line(0,  i, p_getmaxx(),  i);
  317.     for (i = 100; i < p_getmaxx(); i += 100)
  318.         p_line( i, 0,  i, p_getmaxy());
  319.  
  320.     printf("Printing Triplex\n");
  321.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
  322.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  323.     p_outtextxy(100, 50, "Triplex left top");
  324.  
  325.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  326.     p_outtextxy(300, 50, "Triplex left centre");
  327.  
  328.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  329.     p_outtextxy(500, 50, "Triplex left bottom");
  330.  
  331.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  332.     p_outtextxy(100, 100, "Triplex centre top");
  333.  
  334.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  335.     p_outtextxy(300, 100, "Triplex centre centre");
  336.  
  337.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  338.     p_outtextxy(500, 100, "Triplex centre bottom");
  339.  
  340.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  341.     p_outtextxy(100, 150, "Triplex right top");
  342.  
  343.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  344.     p_outtextxy(300, 150, "Triplex right centre");
  345.  
  346.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  347.     p_outtextxy(500, 150, "Triplex right bottom");
  348.  
  349.     printf("Printing Default\n");
  350.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  351.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  352.     p_outtextxy(200, 25, "Default left top");
  353.  
  354.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  355.     p_outtextxy(400, 25, "Default left centre");
  356.  
  357.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  358.     p_outtextxy(600, 25, "Default left bottom");
  359.  
  360.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  361.     p_outtextxy(200, 75, "Default centre top");
  362.  
  363.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  364.     p_outtextxy(400, 75, "Default centre centre");
  365.  
  366.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  367.     p_outtextxy(600, 75, "Default centre bottom");
  368.  
  369.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  370.     p_outtextxy(200, 125, "Default right top");
  371.  
  372.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  373.     p_outtextxy(400, 125, "Default right centre");
  374.  
  375.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  376.     p_outtextxy(600, 125, "Default right bottom");
  377.  
  378.     end_slice();
  379. }
  380.  
  381. /********************************************************************
  382.  Print stroked and default font vertically, using various
  383.  justification settings */
  384.  
  385. void vert_text_demo(void)
  386. {
  387. int i;
  388.  
  389.     printf("\n\nVERTICAL JUSTIFICATION DEMO\n\n");
  390.     p_setviewport(0, 0, 642, 180, 1);
  391.     p_setlinestyle(DOTTED_LINE, 0, NORM_WIDTH);
  392.     for (i = 25; i <= 150; i += 25)
  393.         p_line(0,  i, p_getmaxx(),  i);
  394.     for (i = 20; i < p_getmaxx(); i += 20)
  395.         p_line( i, 0,  i, p_getmaxy());
  396.  
  397.     printf("Printing Triplex\n");
  398.     p_settextstyle(TRIPLEX_FONT, VERT_DIR, 1);
  399.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  400.     p_outtextxy(100, 50, "Triplex left top");
  401.  
  402.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  403.     p_outtextxy(300, 50, "Triplex left centre");
  404.  
  405.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  406.     p_outtextxy(500, 50, "Triplex left bottom");
  407.  
  408.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  409.     p_outtextxy(120, 100, "Triplex centre top");
  410.  
  411.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  412.     p_outtextxy(320, 100, "Triplex centre centre");
  413.  
  414.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  415.     p_outtextxy(520, 100, "Triplex centre bottom");
  416.  
  417.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  418.     p_outtextxy(140, 150, "Triplex right top");
  419.  
  420.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  421.     p_outtextxy(340, 150, "Triplex right centre");
  422.  
  423.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  424.     p_outtextxy(540, 150, "Triplex right bottom");
  425.  
  426.     printf("Printing Default\n");
  427.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 1);
  428.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  429.     p_outtextxy(200, 25, "Default left top");
  430.  
  431.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  432.     p_outtextxy(400, 25, "Default left centre");
  433.  
  434.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  435.     p_outtextxy(600, 25, "Default left bottom");
  436.  
  437.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  438.     p_outtextxy(220, 75, "Default centre top");
  439.  
  440.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  441.     p_outtextxy(420, 75, "Default centre centre");
  442.  
  443.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  444.     p_outtextxy(620, 75, "Default centre bottom");
  445.  
  446.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  447.     p_outtextxy(240, 125, "Default right top");
  448.  
  449.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  450.     p_outtextxy(440, 125, "Default right centre");
  451.  
  452.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  453.     p_outtextxy(640, 125, "Default right bottom");
  454.  
  455.     end_slice();
  456. }
  457.  
  458. /********************************************************************
  459.  Print stroked font, using various scaling factors */
  460.  
  461. void text_scaling_demo(void)
  462. {
  463. struct textsettingstype texttypeinfo;
  464. int lomode, himode;
  465.  
  466.     printf("\n\nTEXT SCALING DEMO\n\n");
  467.     p_setviewport(0, 0, 660, 190, 1);
  468.     p_settextstyle(TRIPLEX_FONT, VERT_DIR, 1);
  469.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  470.  
  471.     p_gettextsettings(&texttypeinfo);
  472.     printf("Text set to font no. %d, direction = %s, size = %d\n",
  473.         texttypeinfo.font,
  474.         texttypeinfo.direction == HORIZ_DIR ? "Horizontal" : "Vertical",
  475.         texttypeinfo.charsize);
  476.     printf("Text justification is %s, %s\n",
  477.         texttypeinfo.horiz == LEFT_TEXT ? "Left" : texttypeinfo.horiz == CENTER_TEXT ? "Centre" : "Right",
  478.         texttypeinfo.vert  == TOP_TEXT  ? "Top"  : texttypeinfo.vert  == CENTER_TEXT ? "Centre" : "Bottom");
  479.  
  480.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
  481.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  482.  
  483.     p_gettextsettings(&texttypeinfo);
  484.     printf("Text set to font no. %d, direction = %s, size = %d\n",
  485.         texttypeinfo.font,
  486.         texttypeinfo.direction == HORIZ_DIR ? "Horizontal" : "Vertical",
  487.         texttypeinfo.charsize);
  488.     printf("Text justification is %s, %s\n",
  489.         texttypeinfo.horiz == LEFT_TEXT ? "Left" : texttypeinfo.horiz == CENTER_TEXT ? "Centre" : "Right",
  490.         texttypeinfo.vert  == TOP_TEXT  ? "Top"  : texttypeinfo.vert  == CENTER_TEXT ? "Centre" : "Bottom");
  491.  
  492.     p_setusercharsize(3, 2, 1, 2);
  493.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
  494.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  495.     p_outtextxy(0, 0, "Treble width, Normal height");
  496.     p_setusercharsize(1, 2, 1, 2);
  497.     p_outtextxy(0, 15, "Normal width, Normal height");
  498.     p_setusercharsize(1, 2, 3, 2);
  499.     p_outtextxy(0, 25, "Normal width, Treble height");
  500.     p_setusercharsize(3, 2, 3, 2);
  501.     p_outtextxy(0, 60, "Treble width, Treble height");
  502.     p_setusercharsize(1, 6, 1, 2);
  503.     p_outtextxy(0, 110, "1/3 width, Normal height");
  504.     p_setusercharsize(1, 2, 1, 6);
  505.     p_outtextxy(0, 140, "Normal width, 1/3 height");
  506.     p_setusercharsize(1, 6, 1, 6);
  507.     p_outtextxy(0, 170, "1/3 width, 1/3 height");
  508.  
  509.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
  510.     printf("Width, height of 'ABC' in Triplex size  1 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  511.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 10);
  512.     printf("Width, height of 'ABC' in Triplex size 10 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  513.  
  514.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  515.     printf("Width, height of 'ABC' in Default size  1 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  516.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 10);
  517.     printf("Width, height of 'ABC' in Default size 10 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  518.  
  519.     printf("Current graph mode    = %d\n", p_getgraphmode());
  520.     printf("Maximum graph mode    = %d\n", p_getmaxmode());
  521.     printf("Graph mode name       = %Fs\n", p_getmodename(p_getgraphmode()));
  522.     p_getmoderange(STAR, &lomode, &himode);
  523.     printf("Star NX-10 mode range = %d -- %d\n", lomode, himode);
  524.  
  525.     end_slice();
  526. }
  527.  
  528. /********************************************************************
  529.  Fill various shapes with various patterns */
  530.  
  531. void shape_fill_demo(void)
  532. {
  533. int i, xasp, yasp;
  534. static int polypoints[] = {
  535.     500, 10,
  536.     500, 190,
  537.     450, 100,
  538.     400, 100,
  539.     350, 180,
  540.     360, 20,
  541.     400, 20,
  542.     420, 70,
  543.     370, 100,
  544.     450, 20,
  545.     500, 10
  546.     };
  547. struct fillsettingstype fillinfo;
  548. static char user_pattern[8] =  "\xf0\x0f\xf0\x0f\xf0\x0f\xf0\x0f";
  549. char user_pattern2[8];
  550.  
  551.     printf("\n\nSHAPE FILLING DEMO\n\n");
  552.     printf("Printing in default viewport\n");
  553.     p_graphdefaults();
  554.     p_getaspectratio(&xasp, &yasp);
  555.     for (i = 0; i < 7; i++) {
  556.         p_setfillstyle(i, 1);
  557.         p_getfillsettings(&fillinfo);
  558.         printf("Fill style set to %d, colour %d\n", fillinfo.pattern, fillinfo.color);
  559.         p_fillellipse( i * 40 + 20, 20, 20, (int)(20L * xasp / yasp));
  560.     }
  561.  
  562.     p_setfillpattern(user_pattern, 1);
  563.     p_getfillpattern(user_pattern2);
  564.     p_getfillsettings(&fillinfo);
  565.     printf("Fill style set to %d, colour %d\n", fillinfo.pattern, fillinfo.color);
  566.     p_fillellipse( i * 40 + 20, 20, 20, (int)(20L * xasp / yasp));
  567.  
  568.     p_setfillstyle(LTSLASH_FILL, 1);
  569.     printf("p_fillpoly(11, polypoints);\n");
  570.     p_fillpoly(11, polypoints);
  571.  
  572.     printf("p_bar(370, 100, 500, 170)\n");
  573.     p_bar(570, 100, 600, 170);
  574.     printf("p_bar3d(0, 100, 50, 150, 25, 1)\n");
  575.     p_bar3d(0, 100, 50, 150, 25, 1);
  576.     printf("p_bar3d(70, 100, 120, 150, 25, 0)\n");
  577.     p_bar3d(70, 100, 120, 150, 25, 0);
  578.     end_slice();
  579. }
  580.  
  581. /********************************************************************
  582.  Fill an arbitrary shape */
  583.  
  584. void flood_fill_demo(void)
  585. {
  586. static int polypoints[] = {
  587.     200, 10,
  588.     200, 190,
  589.     150, 100,
  590.     100, 100,
  591.      50, 180,
  592.      60, 20,
  593.     100, 20,
  594.     120, 70,
  595.      70, 100,
  596.     150, 20,
  597.     200, 10
  598.     };
  599.  
  600.     printf("\n\nFLOOD FILLING DEMO\n\n");
  601.     p_setviewport(0, 0, 719, 199, 1);
  602.     p_setcolor(1);
  603.     printf("Drawing polygon\n");
  604.     p_drawpoly(11, polypoints);
  605.     printf("Including a circle\n");
  606.     p_circle(150, 80, 10);
  607.     printf("Filling polygon\n");
  608.     p_floodfill(165, 80, 1);
  609.  
  610.     end_slice();
  611. }
  612.  
  613. /********************************************************************
  614.  Draw various lines in different directions, with a user-defined
  615.  pattern */
  616.  
  617. void lines_demo(void)
  618. {
  619. int i;
  620. struct linesettingstype linetypeinfo;
  621.  
  622.     printf("\n\nLINE DRAWING DEMO\n\n");
  623.     p_setviewport(0, 0, 719, 199, 1);
  624.     p_setlinestyle(USERBIT_LINE, 0xfc02, THICK_WIDTH);
  625.     for (i = 0; i <= 100; i += 20) {
  626.         p_line(0, 0, 100, i);
  627.         p_line(319, 0, 200, i);
  628.         p_line(i, 199, 100, 100);
  629.         p_line(200, 199, 319-i, 100);
  630.     }
  631.     p_getlinesettings(&linetypeinfo);
  632.     printf("Current line settings: \n\tLine stype = %d\n\tUser pattern = %04x\n\
  633. \tThickness = %d\n\n", linetypeinfo.linestyle, linetypeinfo.upattern, linetypeinfo.thickness);
  634.  
  635.     end_slice();
  636. }
  637.  
  638. /********************************************************************
  639.  Draw an elliptical pie chart on the printer. */
  640.  
  641. static void draw_elliptical_pie(void)
  642. {
  643.     p_setviewport(0, 0, 500, 120, 1);
  644.     p_outtextxy(300, 50, "Elliptical Pie chart");
  645.     p_setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
  646.     p_setfillstyle(CLOSE_DOT_FILL, 1);
  647.     p_sector(150, 50, 0, 50, 75, 30);
  648.     p_setfillstyle(HATCH_FILL, 1);
  649.     p_sector(150, 50, 50, 120, 75, 30);
  650.     p_setfillstyle(XHATCH_FILL, 1);
  651.     p_sector(150, 50, 120, 190, 75, 30);
  652.     p_setfillstyle(WIDE_DOT_FILL, 1);
  653.     p_sector(150, 50, 190, 290, 75, 30);
  654.     p_setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
  655.     p_setfillstyle(INTERLEAVE_FILL, 1);
  656.     p_sector(160, 60, 290, 360, 75, 30);
  657. }
  658.  
  659. /********************************************************************
  660.  Draw a circular pie chart on the printer. */
  661.  
  662. void pie_demo(void)
  663. {
  664.     printf("\n\nPIE CHART DRAWING DEMO\n\n");
  665.     p_setviewport(0, 0, 500, 200, 1);
  666.     printf("Circular pie chart, various fill patterns\n");
  667.     p_outtextxy(300, 100, "Circular Pie chart");
  668.     printf("Slice 1, CLOSE DOT FILL.\n");
  669.     p_setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
  670.     p_setfillstyle(CLOSE_DOT_FILL, 1);
  671.     p_pieslice(150, 100, 0, 50, 75);
  672.     printf("Slice 2, HATCH FILL.\n");
  673.     p_setfillstyle(HATCH_FILL, 1);
  674.     p_pieslice(150, 100, 50, 120, 75);
  675.     printf("Slice 3, XHATCH FILL.\n");
  676.     p_setfillstyle(XHATCH_FILL, 1);
  677.     p_pieslice(150, 100, 120, 190, 75);
  678.     printf("Slice 4, WIDE DOT FILL.\n");
  679.     p_setfillstyle(WIDE_DOT_FILL, 1);
  680.     p_pieslice(150, 100, 190, 290, 75);
  681.     printf("Slice 5, INTERLEAVE FILL.\n");
  682.     p_setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
  683.     p_setfillstyle(INTERLEAVE_FILL, 1);
  684.     p_pieslice(160, 110, 290, 360, 75);
  685.  
  686.     end_slice();
  687.  
  688.     printf("Elliptical pie chart, various fill patterns\n");
  689.     draw_elliptical_pie();
  690.     end_slice();
  691. }
  692.  
  693. #if defined(LARGE_CODE)
  694. /********************************************************************
  695.  Scale an image to best fit the aspect ratio of the printer. This only
  696.  works if the resulting xaspect >= yaspect */
  697.  
  698. static int scale_image(void far *bitmap, int xscale)
  699. {
  700. int x, y, right, bottom, old_width;
  701. int new_width, new_x;
  702. int source, dest, pixel;
  703. int far *header = bitmap;
  704. char far *data = (char far *) bitmap + 4;
  705.  
  706.     if (xscale == 0) return 0;
  707.     right = header[0];
  708.     bottom = header[1];
  709.     old_width = (right+8) / 8;
  710.     new_width = (old_width + xscale - 1)/xscale;
  711.     header[0] = new_width * 8 - 1;
  712.     for (y = 0; y <= bottom; y++) {
  713.         for (x = new_x = 0; x <= right; x += xscale, new_x++) {
  714.             source = y * old_width + x/8;
  715.             dest = y * new_width + new_x/8;
  716.             pixel = (data[source] >> (7 - (x & 7))) & 1;
  717.             data[dest] &= 0xFF7F >> (new_x & 7);
  718.             data[dest] |= (pixel << (7 - (new_x & 7)));
  719.         }
  720.     }
  721.     return 1;
  722. }
  723.  
  724.  
  725. extern int far face[];        /* Image of Anne's face, originally digitised on a Mac */
  726.  
  727.  
  728. /********************************************************************
  729.  Display Anne's face on the printer and screen, firstly unscaled (it
  730.  was saved as an image from a CGA screen via getimage), then scaled
  731.  to fit the printer's aspect ratio as near as possible. In between,
  732.  use putimage & getimage, and p_putimage & p_getimage, to swap characters
  733.  from the printer buffer to screen and vice versa. */
  734.  
  735. void image_demo(void)
  736. {
  737. char imagep[130], imageg[130];
  738. unsigned sizep;
  739. int xaspp, yaspp;
  740. int depth, width, left;
  741.  
  742.     printf("\n\nPICTURE DRAWING DEMO\n\n");
  743.     width = face[0];
  744.     depth = face[1];
  745.     left = (MAX_WIDTH - width)/2;
  746.     p_setviewport(left, 0, left + width, depth, 1);
  747.  
  748.     sizep = p_imagesize(50, 20, 60, 30);
  749.     printf("Image size = %u bytes\n", sizep);
  750.  
  751.     start_screen_output();
  752.     p_putimage(0, 0, face, NOT_PUT);
  753.     end_slice();
  754.  
  755. #ifdef __TURBOC__
  756.     CLS;
  757.     outtextxy(0,100, "Getimage/putimage swapping screen/printer");
  758.     p_outtextxy(50, 20, "F");
  759.     outtextxy(50, 20, "G");
  760.     p_getimage(50, 20, 60, 30, imagep);
  761.     getimage(50, 20, 60, 30, imageg);
  762.     p_putimage(60, 20, imageg, COPY_PUT);
  763.     putimage(60, 20, imagep, COPY_PUT);
  764.     end_slice();
  765.     CLS;
  766.  
  767.     p_getaspectratio(&xaspp, &yaspp);
  768.     if (scale_image(face, (int)((12L * xaspp)/(yaspp * 5L)))) {
  769.         outtextxy(0,180, "Printing Scaled image");
  770.         p_outtextxy(0,150, "Scaled");
  771.         p_putimage(0, 0, (char far *)face, NOT_PUT);
  772.         end_slice();
  773.     } else {
  774.         outtextxy(0, 180, "Can't scale image -- Press a key to continue");
  775.         getch();
  776.     }
  777. #else   /* If not Turbo C */
  778.     CLS;
  779.     p_outtextxy(50, 20, "F");
  780.     p_getimage(50, 20, 60, 30, imagep);
  781.     _getimage(50, 20, 60, 30, imageg);
  782.     p_putimage(60, 20, imageg, COPY_PUT);
  783.     _putimage(60, 20, imagep, COPY_PUT);
  784.     end_slice();
  785.     CLS;
  786.  
  787.     p_getaspectratio(&xaspp, &yaspp);
  788.     if (scale_image(face, (int)((12L * xaspp)/(yaspp * 5L)))) {
  789.         p_outtextxy(0,150, "Scaled");
  790.         p_putimage(0, 0, face, NOT_PUT);
  791.         end_slice();
  792.     } else {
  793.         printf("Can't scale image -- Press a key to continue");
  794.         getch();
  795.     }
  796. #endif
  797.     stop_screen_output();
  798. }
  799.  
  800. /********************************************************************
  801.  Draw a circular pie chart on the printer, then display it on the
  802.  screen. */
  803.  
  804. void view_demo(void)
  805. {
  806.     printf("\n\nIMAGE VIEWING DEMO\n\n");
  807.     printf("Viewing Elliptical pie chart, various fill patterns\n");
  808.     draw_elliptical_pie();
  809.     start_screen_output();
  810.     p_view();
  811. #ifdef __TURBOC__
  812.     outtextxy(0, 180, "Press a key to continue");
  813. #else
  814.     printf("Press a key to continue");
  815. #endif
  816.     getch();
  817.     stop_screen_output();
  818. }
  819.  
  820. /********************************************************************
  821.  Switch screen to graphics mode, and start echoing printer output to
  822.  the screen. */
  823.  
  824. void start_screen_output(void)
  825. {
  826. #ifdef __TURBOC__
  827. int driver = DETECT, mode;
  828.     detectgraph(&driver,&mode);
  829.     switch(driver) {
  830.     case VGA:
  831.     case EGA:
  832.         driver = CGA;
  833.     case CGA:
  834.         registerbgidriver(CGA_driver);
  835.         mode = CGAHI;
  836.         break;
  837.     case HERCMONO:
  838.         registerbgidriver(Herc_driver);
  839.         mode = HERCMONOHI;
  840.         break;
  841.     case ATT400:
  842.         mode = ATT400HI;
  843.         break;
  844.     case PC3270:
  845.         mode = PC3270HI;
  846.         break;
  847.     case MCGA:
  848.         mode = MCGAHI;
  849.         break;
  850.     }
  851.     initgraph(&driver, &mode, NULL);
  852.     if (driver < 0) {
  853.         printf("BGI Error: %s\n", grapherrormsg(graphresult()));
  854.         exit(1);
  855.     }
  856. #else
  857.     _setvideomode(_HRESBW);
  858. #endif
  859.     _p_putpixel_screen = (void far *) putpixel;
  860. }
  861.  
  862. /********************************************************************
  863.  Switch screen back to text mode, and stop echoing printer output to
  864.  the screen. */
  865.  
  866. void stop_screen_output(void)
  867. {
  868. #ifdef __TURBOC__
  869.     closegraph();
  870. #else
  871.     _setvideomode(_DEFAULTMODE);
  872. #endif
  873.     _p_putpixel_screen = NULL;
  874. }
  875.  
  876. #ifndef __TURBOC__
  877.  
  878. /********************************************************************
  879.  Output a pixel to the screen */
  880.  
  881. void far putpixel(int x, int y, int colour)
  882. {
  883.     _setcolor(colour);
  884.     _setpixel(x, y);
  885. }
  886. #endif
  887. #endif
  888.